package com.TripMate.system.service.impl;

import com.TripMate.system.common.ErrorCode;
import com.TripMate.system.exception.BusinessException;
import com.TripMate.system.mapper.PostMapper;
import com.TripMate.system.model.dto.post.PostQueryRequest;
import com.TripMate.system.model.entity.Post;
import com.TripMate.system.model.vo.AiHistoryVO;
import com.TripMate.system.model.vo.PostVO;
import com.TripMate.system.service.PostService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author dongmianyan
* @description 针对表【post(文案表)】的数据库操作Service实现
* @createDate 2024-11-30 11:38:04
*/
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post>
    implements PostService {

    @Resource
    private PostMapper postMapper;

    @Override
    public Page<PostVO> getQueryByAll(Page<PostVO> pageParam, PostQueryRequest postQueryRequest) {
        // 自定义分页查询
        List<PostVO> postVOS = postMapper.getQueryByAll(pageParam, postQueryRequest);
        if (postVOS != null) {
            pageParam.setRecords(postVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }

    }

    @Override
    public Page<PostVO> getQueryByMy(Page<PostVO> pageParam, PostQueryRequest postQueryRequest, Long userId) {
        // 自定义分页查询
        List<PostVO> postVOS = postMapper.getQueryByMy(pageParam, postQueryRequest, userId);
        if (postVOS != null) {
            pageParam.setRecords(postVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }
}




